package in.co.codedoc.idcontainer.tests;

import in.co.codedoc.idcontainer.IdSet;
import in.co.codedoc.tests.JUNitTestBase;

import org.junit.Test;
import static org.junit.Assert.*;

public class IdSetTests
	extends JUNitTestBase
{
	@Test
	public void TestNullSet()
	{
		IdSet<FooId> fooIdSet1 = new IdSet<FooId>();
		
		fooIdSet1.Save();
		
		IdSet<FooId> fooIdSet2 = new IdSet<FooId>();
		
		fooIdSet2.Save();
		
		assertTrue(fooIdSet1.GetId().equals(fooIdSet2.GetId()));
	}
	
	@Test
	public void TestOrderInsensitivity()
	{
		IdSet<FooId> fooIdSet1 = new IdSet<FooId>();
		fooIdSet1.Add(FooId.Create(1));
		fooIdSet1.Add(FooId.Create(2));
		fooIdSet1.Save();
		
		IdSet<FooId> fooIdSet2 = new IdSet<FooId>();
		fooIdSet2.Add(FooId.Create(2));
		fooIdSet2.Add(FooId.Create(1));
		fooIdSet2.Save();
		
		assertTrue(fooIdSet1.GetId().equals(fooIdSet2.GetId()));
	}
	
	@Test
	public void TestBasicOps()
	{
		IdSet<FooId> fooIdSet1 = new IdSet<FooId>();
		fooIdSet1.Add(FooId.Create(1));
		fooIdSet1.Add(FooId.Create(2));
		fooIdSet1.Save();
		
		IdSet<FooId> fooIdSet2 = new IdSet<FooId>();
		fooIdSet2.Add(FooId.Create(2));
		fooIdSet2.Add(FooId.Create(3));
		fooIdSet2.Save();
		
		assertFalse(fooIdSet1.GetId().equals(fooIdSet2.GetId()));
		
		fooIdSet2.Remove(FooId.Create(3));
		fooIdSet2.Add(FooId.Create(1));
		fooIdSet2.Save();
		
		assertTrue(fooIdSet1.GetId().equals(fooIdSet2.GetId()));
	}
}
